﻿namespace DomainServices.Tools.Pdb.SymStore
{
    using System;
    using System.Diagnostics.SymbolStore;
    using System.Text;

    internal class SymNamespace : ISymbolNamespace
    {
        private ISymUnmanagedNamespace m_unmanagedNamespace;

        internal SymNamespace(ISymUnmanagedNamespace nameSpace)
        {
            if (nameSpace == null)
            {
                throw new ArgumentNullException("nameSpace");
            }
            this.m_unmanagedNamespace = nameSpace;
        }

        public ISymbolNamespace[] GetNamespaces()
        {
            int pcNameSpaces = 0;
            this.m_unmanagedNamespace.GetNamespaces(0, out pcNameSpaces, null);
            ISymUnmanagedNamespace[] namespaces = new ISymUnmanagedNamespace[pcNameSpaces];
            this.m_unmanagedNamespace.GetNamespaces(pcNameSpaces, out pcNameSpaces, namespaces);
            ISymbolNamespace[] namespaceArray2 = new ISymbolNamespace[pcNameSpaces];
            for (uint i = 0; i < pcNameSpaces; i++)
            {
                namespaceArray2[i] = new SymNamespace(namespaces[i]);
            }
            return namespaceArray2;
        }

        public ISymbolVariable[] GetVariables()
        {
            int pcVars = 0;
            this.m_unmanagedNamespace.GetVariables(0, out pcVars, null);
            ISymUnmanagedVariable[] pVars = new ISymUnmanagedVariable[pcVars];
            this.m_unmanagedNamespace.GetVariables(pcVars, out pcVars, pVars);
            ISymbolVariable[] variableArray2 = new ISymbolVariable[pcVars];
            for (uint i = 0; i < pcVars; i++)
            {
                variableArray2[i] = new SymVariable(pVars[i]);
            }
            return variableArray2;
        }

        public string Name
        {
            get
            {
                int pcchName = 0;
                this.m_unmanagedNamespace.GetName(0, out pcchName, null);
                StringBuilder szName = new StringBuilder(pcchName);
                this.m_unmanagedNamespace.GetName(pcchName, out pcchName, szName);
                return szName.ToString();
            }
        }
    }
}

